package com.cskaoyan.config;

import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
import org.springframework.stereotype.Component;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;

/**
 * @author stone
 * @date 2021/12/03 10:55
 */
//@Component
public class MarketSessionManager extends DefaultWebSessionManager {

    //写这个key去看前端应用的请求头
    String tokenHeader = "X-CskaoyanMarket-Admin-Token";

    @Override
    protected Serializable getSessionId(ServletRequest request, ServletResponse response) {
        HttpServletRequest hsRequest = (HttpServletRequest) request;
        String sessionId = hsRequest.getHeader(tokenHeader);
        if (sessionId != null && !"".equals(sessionId)) {
            return sessionId;
        }
        return super.getSessionId(request, response);
    }
}
